package auxiliares;

import business.Panorama;
import java.util.ArrayList;

/**
 *
 * @author Evangelista
 */
public class PhotoWinners {
    
    private ArrayList<Panorama> winners = new ArrayList<Panorama>();
    private ArrayList<Integer>  matches = new ArrayList<Integer> ();
    
    // OO    
    public ArrayList<Panorama> get_winners(){ return this.winners; }
    public ArrayList<Integer>  get_matches(){ return this.matches; }
    
    public void set_winners( ArrayList<Panorama> winners ){ this.winners = winners; }
    public void set_matches( ArrayList<Integer>  matches ){ this.matches = matches; }
    
    //
    public void add_winner( Panorama winner, int number_matches ){
        this.winners.add(winner        );
        this.matches.add(number_matches);
        sort_by_match();
    }
    
    public void sort_by_match(){
        Panorama aux_winner;
        Integer  aux_match;
        
        boolean ordem = false;
        while(!ordem){
            ordem = true;
            for( int i = 0; i < winners.size() - 1; i++ ){
                if( matches.get(i) > matches.get(i+1) ){
                    ordem = false;
                    aux_match  = matches.get(i);
                    aux_winner = winners.get(i);
                    matches.set(i, matches.get(i+1));
                    winners.set(i, winners.get(i+1));
                    matches.set(i+1, aux_match);
                    winners.set(i+1, aux_winner);
                }
            }
        }
    }
    
    public ArrayList<Panorama> get_winners( int percentage ){
        ArrayList<Panorama> ret = new ArrayList<Panorama>();
        int range_percentage = (int)( matches.get(0) * ( percentage / 10 ) );
        
        int i = 0;
        int current_match = matches.get(i);
        while( i < winners.size() && current_match >= matches.get(0) - range_percentage ){
            ret.add(winners.get(i++));
            current_match = matches.get(i);
        }
        
        return ret;
    }
    
}
